<?php

!defined('IN_APP') && exit('Access Denied');

class admin_maincontrol extends controlbase {


    function ondefault() {
        
        include template('index');
        
    }

    function onheader() {
        include template('header');
    }

    function onmenu() {
        include template('menu');
    }

    function onstat() {
    	$eventcount=$this->db->selectCollection('event')->count();
        $usercount=$this->db->selectCollection('user')->count();
        
		$dbstats = $this->db->execute('db.stats()');
        $dbsize = $dbstats['retval']['storageSize'];
        $dbsize = $dbsize ? $this->_sizecount($dbsize) : '未知';

        $serverinfo = PHP_OS.' / PHP v'.PHP_VERSION;
        $serverinfo .= @ini_get('safe_mode') ? ' Safe Mode' : NULL;
        $fileupload = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : '<font color="red">否</font>';

        $mongodb_info = $this->db->command(array('buildinfo'=>true));
		$dbversion = $mongodb_info['version'];
		
        $magic_quote_gpc = get_magic_quotes_gpc() ? 'On' : 'Off';
        $allow_url_fopen = ini_get('allow_url_fopen') ? 'On' : 'Off';
        include template('stat');
    }


    function _sizecount($filesize) {
        if($filesize >= 1073741824) {
            $filesize = round($filesize / 1073741824 * 100) / 100 . ' GB';
        } elseif($filesize >= 1048576) {
            $filesize = round($filesize / 1048576 * 100) / 100 . ' MB';
        } elseif($filesize >= 1024) {
            $filesize = round($filesize / 1024 * 100) / 100 . ' KB';
        } else {
            $filesize = $filesize . ' Bytes';
        }
        return $filesize;
    }

    function onlogin() {
        $password = md5($this->post['password']);
        $user=$this('user')->get_by_username($this->user['username']);
        if(is_array($user)&&($password==$user['password'])) {
            $this('user')->refresh($user['uid'],2);
            include template('index');
        }else {
            $this->message('用户名或密码错误！', 'admin_main');
        }
    }

    function onlogout() {
        $this('user')->refresh($this->user['uid'],1);
        header("Location:".SITE_URL);
    }
}
